home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7504 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.microsoft.com!news
  2. From: a-cnadc@microsoft.com (Dann Corbit)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Simple Program Question
  5. Date: 27 Feb 1996 03:30:20 GMT
  6. Organization: Microsoft Corporation
  7. Message-ID: <4gttsc$2pr@news.microsoft.com>
  8. References: <4gsr9u$sk6@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: 157.57.171.202
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4gsr9u$sk6@newsbf02.news.aol.com>, tycope@aol.com says...
  14. >
  15. >I am trying to write a non -interactive program that calculates all
  16. >integer triples (i, j, k) such that 
  17. >0 < i < j < k < l and i + j + k = l. Print out the number of triples that
  18. >satisfy the requirements and print out every millionth triple.  Can anyone
  19. >see where I am missing the boat in the following code.  The program runs
  20. >and immediately terminates.  Thanks in advance for any feedback. 
  21. >
  22. >#include <stdio.h>
  23. >
  24. >long int i, j, k, l;
  25. >long int count;
  26. >
  27. >int
  28. >main (void)
  29. >{
  30. >        do
  31. >        {
  32. >                (l = i + j + k);
  33.  
  34.                       ^^^^^^^^^^
  35. Hint: What do i, j, and k contain right here?
  36.  
  37. >                (i = 1);
  38. >                (j = 2);
  39. >                (k = 3);
  40. >                (i++, j++, k++);
  41. >                (++count);
  42. >        if (count % 1000000 == 0)
  43. >         {
  44. >                printf("%ld(i) + %ld(j) + %ld(k) = %ld(l)", i, j, k, l);
  45. >         }
  46. >
  47. >        } while (0 < i < j < k < l);
  48. >
  49. >        return (0);
  50. >}
  51.  
  52. -- 
  53. The opinions expressed in this message are my own personal views
  54. and do not reflect the official views of Microsoft Corporation.
  55. In fact, I'm just a subcontractor, not an employee, so pull in your claws.
  56.  
  57.